import os

def rename_files(folder_path):
    for root, dirs, files in os.walk(folder_path):
        for file_name in files:
            old_path = os.path.join(root, file_name)
            new_name = file_name
            has_number = False
            for char in file_name:
                if char.isdigit():
                    has_number = True
                    break
            if has_number:
                new_name = ""
                for char in file_name:
                    if not (char.isdigit() or char == '_'):
                        new_name += char
            if new_name != file_name:
                new_path = os.path.join(root, new_name)
                try:
                    os.rename(old_path, new_path)
                except FileExistsError:
                    continue


from PIL import Image
import os

def compress_images(folder_path):
    for root, dirs, files in os.walk(folder_path):
        for file_name in files:
            if file_name.endswith(('.jpg', '.jpeg', '.png')):
                image_path = os.path.join(root, file_name)
                img = Image.open(image_path)
                img.save(image_path, optimize=True, quality=75)

folder_path = "F:\留白头像\\头像\\PS类型\\水晶月亮"
compress_images(folder_path)

# folder_path = "F:\留白头像\\头像\\PS类"
# rename_files(folder_path)
# print('修改完成')